package com.wasu.service;

import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping(value="/shiro")
@Controller
public class RolesRelation {
	
	private static Logger log = Logger.getLogger(RolesRelation.class);
	@ResponseBody
	@RequestMapping(value="/queryuser")
	public Set<String> getUser(){
		return OrderJedis.getUsers("users");
	}
	
	@ResponseBody
	@RequestMapping(value="/queryroles")
	public List<String> getRoles(@RequestParam("user") String user){
		log.info("查询用户列表................");
		Subject currentUser = SecurityUtils.getSubject();
		log.info("sessionid:"+currentUser.getSession().getId()+"-------会话时间："+currentUser.getSession().getStartTimestamp());
		return OrderJedis.getValues(user);
	}
	
	@RequestMapping(value="/updateroles")
	@ResponseBody
	public String changeRole(String uid,String role){
		OrderJedis.del(uid);
		String[] values = role.split(",");
		for(String value:values){
			OrderJedis.writeValue(uid, value);
		}
		return "success";
	}

}
